package cn.broadsense.web.controller.biz;

import cn.broadsense.biz.bo.DataItemAuditingBo;
import cn.broadsense.biz.bo.DataItemBo;
import cn.broadsense.biz.bo.DataItemQueryBo;
import cn.broadsense.biz.domain.DataItem;
import cn.broadsense.biz.dto.DataItemDto;
import cn.broadsense.biz.service.DataItemService;
import cn.broadsense.common.annotation.Log;
import cn.broadsense.common.core.controller.BaseController;
import cn.broadsense.common.core.domain.R;
import cn.broadsense.common.core.page.TableDataInfoResult;
import cn.broadsense.common.enums.BusinessType;
import cn.broadsense.common.utils.uuid.Seq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: pengxin
 * @create: 2024-09-12 16:47
 * @Version 1.0
 **/
@RestController
@RequestMapping("/dataItem")
@Api(tags = "事项数据采集")
@RequiredArgsConstructor
public class DataItemController extends BaseController {

    private final DataItemService dataItemService;

    @GetMapping("/list")
    @ApiOperation(value = "获取事项数据列表", notes = "获取事项数据列表")
    public TableDataInfoResult<List<DataItem>> list(DataItemQueryBo queryBo) {
        startPage();
        List<DataItem> list = dataItemService.findList(queryBo);
        return getDataTableResult(list);
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存事项数据", notes = "保存事项数据")
    @Log(title = "事项数据-保存事项数据", businessType = BusinessType.INSERT)
    public R<Void> save(@RequestBody @Validated DataItemBo dataItem) {
        dataItemService.saveDataItem(dataItem);
        return R.ok();
    }

    @DeleteMapping("/remove/{id}")
    @ApiOperation(value = "删除事项数据", notes = "删除事项数据")
    @Log(title = "事项数据-删除事项数据", businessType = BusinessType.DELETE)
    public R<Void> remove(@PathVariable Long id) {
        dataItemService.removeById(id);
        return R.ok();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "获取事项数据详情", notes = "获取事项数据详情")
    public R<DataItemDto> detail(@PathVariable Long id) {
        return R.ok(dataItemService.getDtoById(id));
    }

    @GetMapping("/code")
    @ApiOperation(value = "获取事项数据编码", notes = "获取事项数据编码")
    public R<String> getCode() {
        return R.ok(Seq.generateDataItemCode());
    }


    @ApiOperation(value = "事项数据审核", notes = "事项数据审核")
    @PutMapping("/auditing")
    public R<Void> auditing(@RequestBody @Validated DataItemAuditingBo dataItemAuditingBo) {
        dataItemService.auditing(dataItemAuditingBo);
        return R.ok();
    }

}
